
var gizmo;
 
var day = new Array("CN", "T2","T3", "T4", "T5",	"T6","T7");
var mon = new Array("12", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11");
var de = new Array("st", "nd", "rd", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th", "th", "st");

function stopClock(){
  clearTimeout(gizmo);
}
 
function yourClock(){
  var nd = new Date();
  var h, m;
  var s;
  var time = " ";
  h = nd.getHours();
  m = nd.getMinutes();
  s = nd.getSeconds();
	dn = day[nd.getDay()];
	d = nd.getDate();
	d = (d < 10)?"0"+d:d;
	mo = nd.getMonth()+1; //mon[nd.getMonth()];
	y = nd.getFullYear();
	mo = (mo < 10)?"0"+mo:mo;
  if (h <= 9) h = "0" + h;
  if (m <= 9) m = "0" + m;
  if (s <= 9) s = "0" + s;
	var don="AM"
	if (h>=12){don = "PM"}
	if (h>12){h -= 12}
  time += dn + ", ng&#224;y " + d +  "-" + mo + "-" + y + " | " + h+":"+m+":"+s+" " +don; 
  document.getElementById("dateTime").innerHTML = time;
  gizmo = setTimeout("yourClock()", 1000);
}

function ShowDiv(i,s, name){
	for(j=1;j<=s;j++){
		if(j==i){
			if(document.getElementById(name+i).style.display=="")
				document.getElementById(name+i).style.display="none";
			else
				document.getElementById(name+i).style.display="";			
		}else{
			document.getElementById(name+j).style.display="none";
		}
	}
}

function ShowDiv2(i,s, name){
	for(j=1;j<=s;j++){
		if(j==i){
			if(document.getElementById(name+i).style.display=="")
				document.getElementById(name+i).style.display="none";
			else
				document.getElementById(name+j).style.display="";			
		}else{
			document.getElementById(name+j).style.display="none";
		}
	}
	
}

function ShowAnswer(i,s){
	for(j=1;j<=s;j++){
		if(j==i){
			if(document.getElementById("row"+i).style.display=="")
				document.getElementById("row"+i).style.display="none";
			else
				document.getElementById("row"+i).style.display="";			
		}else{
			document.getElementById("row"+j).style.display="none";
		}
	}
}

function upImg(qStr)
{
	width=500;
	height=250;
	//----------------------------------
	Url="/upload/upload.php"+qStr;
	//----------------------------------
	window.open(Url,"","toolbar=no,scrollbar=no,status=no,resizable=no,width=" + width + ",height=" + height + ",top="
							+ ((window.screen.availHeight - height)/2) +",left=" + ((window.screen.availWidth - width)/2));
}

function openURL(strURL, w, h)
{
	width=w;
	height=h;
	window.open(strURL,"","toolbar=no,scrollbar=no,status=no,resizable=no,width=" + width + ",height=" + height + ",top="
							+ ((window.screen.availHeight - height)/2) +",left=" + ((window.screen.availWidth - width)/2));
}

function openWindowWithScroll(f, w ,h)
{
	width=w;
	height=h;
	//----------------------------------
	Url=f;	
	//----------------------------------
	window.open(Url,"","toolbar=no,scrollbars=yes,status=yes,resizable=no ,width=" + width + ",height=" + height + ",top="
							+ ((window.screen.availHeight - height)/2) +",left=" + ((window.screen.availWidth - width)/2));
}

function openExchange(){
	width=300;
	height=450;
	window.open("tygia/tygia.php","","toolbar=no,scrollbar=no,status=no,resizable=no,width=" + width + ",height=" + height + ",top="
							+ ((window.screen.availHeight - height)/2) +",left=" + ((window.screen.availWidth - width)/2));
}

function showPreview()

{
if (document.all.txtHinhAnh.value != "")
	document.all.PREVIEWPIC.src=document.all.txtHinhAnh.value ;

else
	document.all.PREVIEWPIC.src='/images/preview.jpg';
}

function enableIt(){
	var obj = document.getElementById("cmdsurvey");
	if(obj.disabled == true){
		obj.disabled = false;
		obj.className = "cmdSelect";
	}
}

function goNow(){
	var str;
	str = document.getElementById("fastLink").value;
	if(str.length > 0){
		window.open(str);
	}
}

var h, w;

function getImgSize(imgSrc)
{
var newImg = new Image();
newImg.src = imgSrc;
h = newImg.height;
w = newImg.width;
}

function openPic(sPicURL){
	getImgSize(sPicURL);
	//alert(h + "---" + w);
	window.open("/realImage.htm?"+sPicURL+"", "", "toolbar=no,scrollbar=no,status=no,resizable=no,HEIGHT="+h+",WIDTH="+w+",TOP="
							+ ((window.screen.availHeight - h)/2) +",LEFT=" + ((window.screen.availWidth - w)/2));
}


function isEmail(s)
{
    if(s=="")
    	return false;
    if(s.indexOf(" ")>0)
    	return false;
    if(s.indexOf("@")==-1)
    	return false;
    var i=1;
    var slen=s.length;
    if(s.indexOf(".")==-1 || s.indexOf(".")==s.length-1)
    	return false;
    if(s.indexOf("..")!=-1)
    	return false;
    if(s.indexOf("@")!=s.lastIndexOf("@"))
    	return false;
    var str="abcdefghijklmnopqrstuvwxyz1234567890@-._ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    for(var j=0;j<s.length;j++)
    	if(str.indexOf(s.charAt(j))==-1)
    		return false;
    return true;
}

function isNumeric(str){
	if (str == "")return false;
	else{
		var validStr = "0123456789";
		for(var i = 0; i < str.length; i++){
			if(validStr.indexOf(str.charAt(i)) == -1)return false;
		}
	}
	return true;
}

function isTelephone(str){
	var validStr = "+- ().0123456789";
	for(var i = 0; i < str.length; i++){
		if(validStr.indexOf(str.charAt(i)) == -1)return false;
	}
	return true;
}

function checkContact(lang){
	if(document.getElementById("txtfullname").value == ""){
		alert((lang=="vn")?"Ban chua nhap thong tin ho va ten!":"Your fullname is required!");
		document.getElementById("txtfullname").focus();
		return false;
	}
	if(!isEmail(document.getElementById("txtemail").value)){
		alert((lang=="vn")?"Dia chi email khong hop le!":"Invalid email address!");
		document.getElementById("txtemail").focus();
		return false;
	}
	if(document.getElementById("txtsubject").value == ""){
		alert((lang=="vn")?"Ban chua nhap tieu de lien he":"Title is required!");
		document.getElementById("txtsubject").focus();
		return false;
	}    
	if(document.getElementById("txtcontent").value == ""){
		alert((lang=="vn")?"Chua co noi dung lien he!":"Content is required!");
		document.getElementById("txtcontent").focus();
		return false;
	}
	return true;
}

function checkBooking(lang){
	if(!document.getElementById("txtLastName").value){
		alert((lang=="vn")?"Ban chua nhap ho!":"Your LastName is required!");
		document.getElementById("txtLastName").focus();
		return false;
	}
	if(!document.getElementById("txtFirstName").value){
		alert((lang=="vn")?"Ban chua nhap ten!":"Your FirstName is required!");
		document.getElementById("txtFirstName").focus();
		return false;
	}
	if(!document.getElementById("txtAddress").value){
		alert((lang=="vn")?"Ban chua nhap dia chi!":"Your Address is required!");
		document.getElementById("txtAddress").focus();
		return false;
	}
	if(!document.getElementById("txtCity").value){
		alert((lang=="vn")?"Ban chua nhap thanh pho!":"Your City is required!");
		document.getElementById("txtCity").focus();
		return false;
	}    
	if(!document.getElementById("txtPhone").value){
		alert((lang=="vn")?"Ban chua nhap so dien thoai!":"Your phone number is required!");
		document.getElementById("txtPhone").focus();
		return false;
	}
	if(!isTelephone(document.getElementById("txtPhone").value)){
		alert((lang=="vn")?"So dien thoai khong hop le!":"Invalid phone number!");
		document.getElementById("txtPhone").focus();
		return false;
	}
	if(!isEmail(document.getElementById("txtEmail").value)){
		alert((lang=="vn")?"Dia chi email khong hop le!":"Invalid email address!");
		document.getElementById("txtEmail").focus();
		return false;
	}
	if(!document.getElementById("txtCheckIn").value){
		alert((lang=="vn")?"Ban chua nhap ngay den!":"Check in date is required!");
		document.getElementById("txtCheckIn").focus();
		return false;
	}
	if(!document.getElementById("txtCheckOut").value){
		alert((lang=="vn")?"Ban chua nhap ngay di!":"Check out date is required!");
		document.getElementById("txtCheckOut").focus();
		return false;
	}
	if(!document.getElementById("txtNOR").value){
		alert((lang=="vn")?"Ban chua nhap so luong phong!":"Number of Rooms is required!");
		document.getElementById("txtNOR").focus();
		return false;
	}
	if(!isNumeric(document.getElementById("txtNOR").value)){
		alert((lang=="vn")?"Ban nhap so khong dung!":"Invalid number!");
		document.getElementById("txtNOR").focus();
		return false;
	}
	return true;
}

function checkSearch(){
	if(document.frm_Search.keyWord.value == ""){
		alert("Ban chua nhap tu khoa!");
		document.frm_Search.keyWord.focus();
		return false;
	}
	return true;
}

function enableIt(){
	var obj = document.getElementById("cmdsurvey");
	if(obj.disabled == true){
		obj.disabled = false;
		//obj.className = "cmdSelect";
	}
}

function limitLength(idDisplay, maxLength, curObj){
	if(document.getElementById(curObj).value){
		var curLength = document.getElementById(curObj).value.length;
		document.getElementById(idDisplay).innerHTML = "Còn lại " + (maxLength - curLength) + " ký tự";
	}
}

function delNote(idDisplay){
	if(document.getElementById(idDisplay)){
		document.getElementById(idDisplay).innerHTML = "";
	}
}

function checkRateStep1(lang){
	room = document.getElementById("selType").value;
	day = document.getElementById("selDay").value;
	month = document.getElementById("selMonth").value;
	year = document.getElementById("selYear").value;
	if(room == "0" && day == "0" && month == "0" && year == "0"){
		f = document.forms["frmBooking"];
		f.action = "?act=booking";
		f.submit();
	}else{
		cd = new Date();
		d = cd.getDate();
		m = cd.getMonth()+1;
		y = cd.getYear();
		blnSub = true;
		if(year < y){
			blnSub = false;
		}else{
			if(month < m){
				blnSub = false;
			}else{
				if(day < d){
					blnSub = false;
				}
			}
		}
		if(blnSub == true){
			f = document.forms["frmBooking"];
			f.action = "?act=booking&rid="+room+"&cid="+day+"/"+month+"/"+year;
			f.submit();
		}else{
			cDate = d+"/"+m+"/"+y;
			alert((lang == "vn")?("Chon ngay khong hop le!\n\nBan phai chon ngay sau ngay hien tai la "+cDate):("Invalid check in date!\n\nCurrent date is "+cDate));
			return false;
		}
	}
}